package com.lottery.ruok.lottrey.bean;

import java.util.ArrayList;
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;

public class OrderObservableList<T> {

    protected final ArrayList<T> list;
    protected final PublishSubject<ArrayList<T>> onAdd;

    public OrderObservableList() {
        this.list = new ArrayList();
        this.onAdd = PublishSubject.create();
    }

    public void addAll(ArrayList<T> value) {
        list.addAll(value);
        onAdd.onNext(list);
    }

    public void add(T value) {
        list.add(value);
        onAdd.onNext(list);
    }

    public void clear() {
        list.clear();
        onAdd.onNext(list);
    }

    public void remove(int pos){
        list.remove(pos);
        onAdd.onNext(list);
    }

    public T get(int pos){
        return list.get(pos);
    }

    public int size(){
        return list.size();
    }

    public ArrayList<T> getList(){
        return list;
    }

    public Observable<ArrayList<T>> getObservable() {
        return onAdd;
    }
}